<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.ResultSet" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>zsample</title>
</head>
<body>
<%
	try {
		String connectionURL = "jdbc:mysql://localhost:3306/sample"; // default mysql port is 3306
		Connection connection = null;
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		connection = DriverManager.getConnection(connectionURL, "root", "1234");
		if(!connection.isClosed()){
			ResultSet rs = null;
			PreparedStatement pstmt = connection.prepareStatement("SELECT * FROM ztable");
		    rs = pstmt.executeQuery();
			
			while (rs.next()) {
				out.print(rs.getString(2));
			}
		}
	} catch (ClassNotFoundException cnfe) {
		cnfe.printStackTrace();
		out.println("CNFE: " + cnfe.getMessage());
	} catch (SQLException sqle) {
		sqle.printStackTrace();
		out.println("SQLE: " + sqle.getMessage());
	}
	
	out.println("<br/>");
	
	String path = request.getRealPath("/");
	path = path.substring(0, path.lastIndexOf("webapps") + 8);
	out.println(path);
%>
</body>
</html>